package com.typhoon.spring_jdbctemplate.cachekey;

import java.lang.reflect.Method;

import org.springframework.cache.interceptor.KeyGenerator;
import org.springframework.stereotype.Component;

import com.alibaba.fastjson.JSON;
import com.typhoon.spring_jdbctemplate.util.MD5Util;

/**
 * 自定义缓存key生成器
 * 
 * @author Typhoon
 * @date 2017-08-29 17:47 Tuesday
 * @since V1.0 
 */
@Component("customKeyGenerator")
public class CustomKeyGenerator implements KeyGenerator {

	@Override
	public Object generate(Object target, Method method, Object... params) {
		String jsonstr = JSON.toJSONString(params);
		//return method.getName()+":"+params.hashCode();
		return method.getName() + ":" +MD5Util.toMD5(jsonstr);
	}
}
